<?php

/**
 * http://developers.facebook.com/docs/reference/plugins/like/
 */
class FacebookLike
{
    const FONT_ARIAL = 'arial';
    const FONT_LUCIDA_GRANDE = 'lucida grande';
    const FONT_SERGOE_UI = 'sergoe ui';
    const FONT_TAHOMA = 'tahoma';
    const FONT_TREBUCHET_MS = 'trebuchet ms';
    const FONT_VERDANA = 'verdana';
    const LAYOUT_STANDARD = 'standard';
    const LAYOUT_BUTTON_COUNT = 'button_count';
    const LAYOUT_BOX_COUNT = 'box_count';
    const COLOR_SCHEME_LIGHT = 'light';
    const COLOR_SCHEME_DARK = 'dark';
    const VERB_LIKE = 'like';
    const VERB_RECOMMEND = 'recommend';
    private $_lang = "en_US";
    private $_page = "";
    private $_showFaces = TRUE;
    private $_width = 450;
    private $_font = ""; //'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
    private $_layout = "standard"; //button_count, box_count
    private $_colorScheme = "light"; //dark
    private $_verb = "like"; //recommend
    private $_isDirty = FALSE;
    private $_button = '';

    function __construct($page = "")
    {
        $this->_page = $page;
    }

    public function __set($name, $value)
    {
        if ($name == 'lang' ||
             $name ==
             'page' ||
             $name ==
             'showFaces' ||
             $name ==
             'width' ||
             $name ==
             'font' ||
             $name ==
             'layout' ||
             $name ==
             'colorScheme' ||
             $name ==
             'verb')
            {
                $var = '_' .
                 $name;
            $this->$var = $value;
            $this->_isDirty = TRUE;
        }
    }

    private function boolToStr($bool)
    {
        return $bool ? "true" : "false";
    }

    public function getButton()
    {
        if ($this->_isDirty)
        {
            $result = '<script src="http://connect.facebook.net/' . $this->_lang . '/all.js#xfbml=1"></script>';
            $result .= '<fb:like href="' . $this->_page . '" ';
            $result .= 'layout="' . $this->_layout . '" ';
            $result .= 'show_faces="' . $this->boolToStr($this->_showFaces) . '" ';
            $result .= 'width="' . $this->_width . '" ';
            $result .= 'action="' . $this->_verb . '" ';
            $result .= 'font="' . $this->_font . '" ';
            $result .= 'colorscheme="' . $this->_colorScheme . '" ';
            $result .= '>';
            $result .= '</fb:like>';
            $this->_button = $result;
            $this->_isDirty = FALSE;
        }
        return $this->_button;
    }

    public function __tostring()
    {
        return $this->getButton();
    }
}
//
// $like = new FacebookLike();
// $like->width = 500;
// echo (string)$like;
?>